<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增抽奖')" />
	<th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">抽奖活动标题：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="lotteryTitle" id="lotteryTitle" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">抽奖活动内容：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="lotteryContent" id="lotteryContent">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">抽奖开始时间：</label>
				<div class="col-sm-8 date">
<!--					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
					<input type="text" class="form-control" name="beginTime" id="laydate-demo-1" placeholder="请选择抽奖开始时间" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">抽奖结束时间：</label>
				<div class="col-sm-8 date">
<!--					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
					<input type="text" class="form-control" name="endTime" id="laydate-demo-2" placeholder="请选择抽奖结束时间" required>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-js" />
	<script type="text/javascript">
		$(function () {
			layui.use('laydate', function(){
				var laydate = layui.laydate;
				laydate.render({
					elem: '#laydate-demo-1',
					type: 'datetime',
					trigger: 'click'
				});
				laydate.render({
					elem: '#laydate-demo-2',
					type: 'datetime',
					trigger: 'click'
				});
			});
		})
		$("#form-role-add").validate({
			rules:{
				onkeyup: false,
				roleName:{
					remote: {
		                url: ctx + "system/role/checkRoleNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"roleName" : function() {
		                		return $.common.trim($("#roleName").val());
		                    }
		                }
		            }
				},
				roleKey:{
					remote: {
		                url: ctx + "system/role/checkRoleKeyUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"roleKey" : function() {
		                        return $.common.trim($("#roleKey").val());
		                    }
		                }
		            }
				}
			},
			messages: {
		        "roleName": {
		            remote: "角色名称已经存在"
		        },
		        "roleKey": {
		            remote: "角色权限已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }
	
		function add() {
			var lotteryTitle = $("input[name='lotteryTitle']").val();
			var lotteryContent = $("input[name='lotteryContent']").val();
			var beginTime = $("input[name='beginTime']").val();
			var endTime = $("input[name='endTime']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "biz/lottery/add",
				data : {
					"lotteryTitle": lotteryTitle,
					"lotteryContent": lotteryContent,
					"beginTime": beginTime,
					"endTime": endTime
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
	</script>
</body>
</html>
